package GateWars;

import Proxy.DataTransferIn;
import java.io.OutputStream;
import java.net.Socket;

public abstract class SendMessage {
	protected final String ACCEPT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n";
	protected final String ACCEPT2 = "Accept-Language: en-gb,en;q=0.5\n";
	protected final String ACCEPT3 = "Accept-Encoding: gzip,deflate\n";
	protected final String ACCEPT4 = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n";
	protected final String KEEPALIVE = "Keep-Alive: 115\n";
	protected final String PROXY = "Proxy-Connection: keep-alive\n";
	protected final String USER = "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.3) Gecko/20110614 Firefox/3.6.18 (.NET CLR 3.5.30729)\n";
	protected final String HOST = "Host: gatewars.com\n";
	protected final String MIDDLE = HOST + USER + ACCEPT + ACCEPT2 + ACCEPT3 + ACCEPT4 + KEEPALIVE + PROXY;
	
	protected String Cookie;
	public int id;
	
	public void BaseBattlefieldMessage(int page)
	{
		String s = "GET http://gatewars.com/battlefield.php?page=" + page + " HTTP/1.1\n" +
				MIDDLE +
				"Referer: http://gatewars.com/base.php\n" +
				"Cookie: PHPSESSID=" + Cookie + "; loginID=" + id + "\n\n";
		new Thread(new sendMessage(s)).start();
		RMessage("http://gatewars.com/battlefield.php?page=" + page);
	}
	
	public void BattlefieldBattlefieldMessage(int page)
	{
		String s = "GET http://gatewars.com/battlefield.php?page=" + page + " HTTP/1.1\n" +
				MIDDLE +
				"Referer: http://gatewars.com/battlefield.php?page=" + (page - 1) + "\n" +
				"Cookie: PHPSESSID=" + Cookie + "; loginID=" + id + "\n\n";
		new Thread(new sendMessage(s)).start();
		RMessage("http://gatewars.com/battlefield.php?page=" + page);
	}
	
	public void JTBattlefieldPageMessage(int Cpage, int Dpage){
		String s = "POST http://gatewars.com/battlefield.php HTTP/1.1\n" +
				"Host: gatewars.com\n" +
				"Proxy-Connection: keep-alive\n" +
				"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1059 Safari/532.5\n" +
				"Referer: http://gatewars.com/battlefield.php?page=" + Cpage + "\n" +
				"Content-Length: " + (32 + ("" + Dpage).length()) + "\n" +
				"Cache-Control: max-age=0\n" +
				"Origin: http://gatewars.com\n" +
				"Content-Type: application/x-www-form-urlencoded\n" +
				"Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\n" +
				"Accept-Encoding: gzip,deflate,sdch\n" +
				"Accept-Language: en-GB,en-US;q=0.8,en;q=0.6\n" +
				"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\n" +
				"Cookie: PHPSESSID=" + Cookie + "; loginID=" + id + "\n\n" +
	
				"page=" + Dpage + "&uID=&search_type=s&search=";
		new Thread(new sendMessage(s)).start();
		RMessage("http://gatewars.com/battlefield.php");
	}
	
	public void RMessage(String r){
		String s = "GET http://gatewars.com/js/js HTTP/1.1\n" +
			"Host: gatewars.com\n" +
			"Proxy-Connection: keep-alive\n" +
			"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)" +
			"Referer: " + r + "\n" +
			"Accept: * /*\n" +
			"Accept-Language: en-gb,en;q=0.5\n" +
			"Accept-Encoding: gzip,deflate\n" +
			"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n" +
			"Keep-Alive: 115\n" +
			"Cookie: PHPSESSID=" + Cookie + "; loginID=" + id + "\n\n";
		new Thread(new sendMessage(s)).start();
	}
	
	private class sendMessage implements Runnable{
		String s;
		public sendMessage(String s){
			this.s = s;
		}
		
		@Override
		public void run() {
			byte[] message = s.getBytes();
			try {
				Socket gwSocket = new Socket("gatewars.com", 80);
				OutputStream os = gwSocket.getOutputStream();
				//System.out.println(s);
				os.write(message);
				os.flush();
				
                new Thread(new DataTransferIn(gwSocket, null)).start();
			} catch (Exception e) {	
//                e.printStackTrace();
            }
		}		
	}
	
	
	
	/*
	GET http://gatewars.com/battlefield.php?page=38 HTTP/1.1
	Host: gatewars.com
	Proxy-Connection: keep-alive
	User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
	Referer: http://gatewars.com/base.php
	Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,* /*;q=0.5
	Accept-Encoding: gzip,deflate,sdch
	Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
	Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
	Cookie: PHPSESSID=009af2fc54dfb756189d81551fe75920; loginID=1960221
	
	GET http://gatewars.com/js/js HTTP/1.1
	Host: gatewars.com
	Proxy-Connection: keep-alive
	User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
	Referer: http://gatewars.com/battlefield.php?page=38
	Accept: * /*
	Accept-Encoding: gzip,deflate,sdch
	Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
	Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
	Cookie: PHPSESSID=009af2fc54dfb756189d81551fe75920; loginID=1960221
	
	GET http://gatewars.com/battlefield.php?page=39&search=&search_type= HTTP/1.1
	Host: gatewars.com
	Proxy-Connection: keep-alive
	User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
	Referer: http://gatewars.com/battlefield.php?page=38
	Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,* /*;q=0.5
	Accept-Encoding: gzip,deflate,sdch
	Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
	Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
	Cookie: PHPSESSID=009af2fc54dfb756189d81551fe75920; loginID=1960221
	
	GET http://gatewars.com/js/js HTTP/1.1
	Host: gatewars.com
	Proxy-Connection: keep-alive
	User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
	Referer: http://gatewars.com/battlefield.php?page=39&search=&search_type=
	Accept: * /*
	Accept-Encoding: gzip,deflate,sdch
	Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
	Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
	Cookie: PHPSESSID=009af2fc54dfb756189d81551fe75920; loginID=1960221
	*/
	
	/*
	 
	 * /* 
	 should not have a space in the above messages.
	 
	*/
}
